#!/bin/bash
clear
RED="\033[31m"    # Error message
GREEN="\033[32m"  # Success message
YELLOW="\033[33m" # Warning message
BLUE="\033[36m"   # Info message
RESET='\033[0m'

if [ "$EUID" -ne 0 ]; then
  echo -e "${RED} Anda tiada kebenaran untuk menjalankan skrip ini! ${RESET}"
  exit 1
fi

wget -q -O /usr/local/bin/dropbear-wbs 'https://raw.githubusercontent.com/cybertize/ndiey/beta/sources/websocket/dropbear-wbs.py'
wget -q -O /usr/local/bin/openvpn-wbs 'https://raw.githubusercontent.com/cybertize/ndiey/beta/sources/websocket/openvpn-wbs.py'
wget -q -O /usr/local/bin/stunnel-wbs 'https://raw.githubusercontent.com/cybertize/ndiey/beta/sources/websocket/stunnel-wbs.py'
chmod +x /usr/local/bin/dropbear-wbs
chmod +x /usr/local/bin/openvpn-wbs
chmod +x /usr/local/bin/stunnel-wbs

echo "[Unit]
Description=Dropbear Websocket
Documentation=https://google.com
After=network.target nss-lookup.target

[Service]
Type=simple
User=root
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
ExecStart=/usr/bin/python -O /usr/local/bin/dropbear-wbs 2095
Restart=on-failure

[Install]
WantedBy=multi-user.target" >/etc/systemd/system/wbs-dropbear.service

echo "[Unit]
Description=OpenVPN Websocket
Documentation=https://google.com
After=network.target nss-lookup.target

[Service]
Type=simple
User=root
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
Restart=on-failure
ExecStart=/usr/bin/python -O /usr/local/bin/openvpn-wbs

[Install]
WantedBy=multi-user.target" >/etc/systemd/system/wbs-openvpn.service

echo "[Unit]
Description=Stunnel Websocket
Documentation=https://google.com
After=network.target nss-lookup.target

[Service]
Type=simple
User=root
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
Restart=on-failure
ExecStart=/usr/bin/python -O /usr/local/bin/stunnel-wbs

[Install]
WantedBy=multi-user.target" >/etc/systemd/system/wbs-stunnel.service

systemctl daemon-reload
systemctl enable wbs-dropbear
systemctl start wbs-dropbear
systemctl enable wbs-openvpn
systemctl start wbs-openvpn
systemctl enable wbs-stunnel
systemctl start wbs-stunnel

echo
echo -e "${GREEN} Pemasangan websocket pakej telah selesai. ${RESET}"
echo
